package com.biter;

import com.biter.loadBtcData.backCall;
import com.biter.bean.KeyValueBean;
import com.biter.bean.MarketItemBean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;

public class MarketItemAdapter extends BaseAdapter {

	private Context mContext = null;
	private KeyValueBean[] marketIdV = null;
	private ListView listView = null;
	private MarketItemBean mibBean = null;
	
	public MarketItemAdapter(Context mContext,KeyValueBean[] marketIdV,ListView listView){
		this.mContext = mContext;
		this.marketIdV = marketIdV;
		this.listView = listView;
	}
	
	@Override
	public int getCount() {
		return marketIdV.length;
	}

	@Override
	public Object getItem(int position) {
		return marketIdV[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		KeyValueBean kvbBean = marketIdV[position];
		if(convertView==null){
			LayoutInflater mInflater = LayoutInflater.from(mContext);
		    convertView = mInflater.inflate(R.layout.listitem, null);
		    convertView.setTag(kvbBean.getValueAtIdx(2));
		}
		
		loadBtcData.getMarketData(kvbBean.getValueAtIdx(2), kvbBean.getValueAtIdx(1), new backCall(){
            
			@Override
			public void setData(String dataJson, String marketTag) {
				
				  View itemView = (View)listView.findViewWithTag(marketTag);
				  mibBean =  new MarketItemBean(itemView);
				  mibBean.setJsonData(dataJson,marketTag);
			}
			
		});
		
		return convertView;
	}
	

}
